<HTML>

<HEAD>
        <META NAME="keywords" CONTENT="electronic commerce, ecommerce, ebusiness, e-business, e-commerce, enterprise software, net economy, Netscape, Sun Microsystems, Sun-Netscape Alliance, iPlanet, internet software">
        <META NAME="description" CONTENT="The Sun-Netscape Alliance, a strategic alliance formed by America Online and Sun Microsystems, Inc., is delivering iPlanet e-commerce software and enterprise solutions that enable companies to compete successfully in the Net Economy">
	<META HTTP-EQUIV="Content-Type" content="text/html; charset=ISO-8859-1">
	<META NAME="TEMPLATEBASE" CONTENT="Authored in FrameMaker. Converted to HTML in WebWorks Publisher 2000. manual wdt 1.5">
	<META NAME="LASTUPDATED" CONTENT="09/28/00 13:17:58">
	<TITLE> Core JavaScript Guide 1.5: 4 Regular Expressions</TITLE>
</HEAD>




<BODY TEXT="#000000" LINK="#666699" VLINK="#666699" ALINK="#333366" BGCOLOR="#FFFFFF">

<MAINCONTENT>

<NAVIGATIONCONTENT>
   <TABLE WIDTH="100%" BORDER="0" CELLSPACING="4">
      <TR>
         <TD VALIGN="TOP">
            <b><a href="expr.html">
<FONT FACE="Arial, Helvetica, sans-serif" SIZE="2" COLOR="#993300">Previous</a></FONT>&nbsp;&nbsp;&nbsp;&nbsp;</b>
<a href="contents.html">
<b><FONT FACE="Arial, Helvetica, sans-serif" SIZE="2" COLOR="#993300">Contents</a></FONT></b>&nbsp;&nbsp;&nbsp;&nbsp;
<a href="ix.html"><b><FONT FACE="Arial, Helvetica, sans-serif" SIZE="2" COLOR="#993300">Index</a></FONT></b>&nbsp;&nbsp;&nbsp;&nbsp;
<a href="stmtsov.html">
<b>
<FONT FACE="Arial, Helvetica, sans-serif" SIZE="2" COLOR="#993300">
Next
</a>
</FONT>
</b>&nbsp;&nbsp;&nbsp;&nbsp;
         </TD>
     </TR>

      <TR>
         <TD VALIGN="TOP" ALIGN="RIGHT" BGCOLOR="#CCCCCC">
            <FONT FACE="Arial, Helvetica, sans-serif" COLOR="#000000" SIZE="2"><B>
             Core JavaScript Guide 1.5</B></FONT>
         </TD>
      </TR>
      <TR>
   </TABLE>
   <BR>
</NAVIGATIONCONTENT>

<BOOKCONTENT>
   <blockquote>
<BR>
<BR>

      <A NAME="1008300"> </A><A NAME=""> </A><FONT FACE="Arial, Helvetica, sans-serif" SIZE="4" COLOR="#666666"><B>
<zchapnumber>Chapter 4 </zchapnumber>
&nbsp;
</B>
</FONT>


<A NAME="1010922"> </A>
<A NAME="Regular Expressions"> </A>
<FONT FACE="Arial, Helvetica, sans-serif" SIZE="4" COLOR="#000000">
<B>
<zchaptitle>Regular Expressions</zchaptitle>
</B>
</FONT>
<BR>
<BR>
<BR>

<A NAME="1012348"> </A><FONT FACE="Arial, Helvetica, sans-serif" SIZE="2"><zparagraph>Regular expressions are patterns used to match character combinations in strings. In JavaScript, regular expressions are also objects. These patterns are used with the <FONT FACE="courier, couriernew, monospaced size">exec</FONT> and <FONT FACE="courier, couriernew, monospaced size">test</FONT> methods of <FONT FACE="courier, couriernew, monospaced size">RegExp</FONT>, and with the <FONT FACE="courier, couriernew, monospaced size">match</FONT>, <FONT FACE="courier, couriernew, monospaced size">replace</FONT>, <FONT FACE="courier, couriernew, monospaced size">search</FONT>, and <FONT FACE="courier, couriernew, monospaced size">split</FONT> methods of <FONT FACE="courier, couriernew, monospaced size">String</FONT>. This chapter describes JavaScript regular expressions.</zparagraph>
</FONT>
<P>
<P>
<A NAME="1012350"> </A>
<FONT FACE="Arial, Helvetica, sans-serif" SIZE="2">
<B>
<zheadrunin>JavaScript 1.1 and earlier. </zheadrunin>
</B>
</FONT>

<A NAME="1012351"> </A><FONT FACE="Arial, Helvetica, sans-serif" SIZE="2"><zparagraph>Regular expressions are not available in JavaScript&nbsp;1.1 and earlier.</zparagraph>
</FONT>
<P>

<A NAME="1009793"> </A><FONT FACE="Arial, Helvetica, sans-serif" SIZE="2"><zparagraph>This chapter contains the following sections:</zparagraph>
</FONT>
<P>
<ul>
<A NAME="1009794"> </A>
<FONT FACE="Arial, Helvetica, sans-serif" SIZE="2">
<B>  <li></B>
<zsmartlist1><A HREF="regexp.html#1008311"  >Creating a Regular Expression</A></zsmartlist1>
</FONT>
<P><A NAME="1009795"> </A>
<FONT FACE="Arial, Helvetica, sans-serif" SIZE="2">
<B>  <li></B>
<zsmartlist1><A HREF="regexp.html#1010689"  >Writing a Regular Expression Pattern</A></zsmartlist1>
</FONT>
<P><A NAME="1009885"> </A>
<FONT FACE="Arial, Helvetica, sans-serif" SIZE="2">
<B>  <li></B>
<zsmartlist1><A HREF="regexp.html#1008506"  >Working With Regular Expressions</A></zsmartlist1>
</FONT>
<P><A NAME="1009891"> </A>
<FONT FACE="Arial, Helvetica, sans-serif" SIZE="2">
<B>  <li></B>
<zsmartlist1><A HREF="regexp.html#1013064"  >Examples</A></zsmartlist1>
</FONT>
<P></ul>

<BR>
<BR>

<A NAME="1008311"> </A>
<A NAME="Creating a Regular Expression"> </A>
<FONT FACE="Arial, Helvetica, sans-serif" SIZE="4">
<zhead1>Creating a Regular Expression</zhead1>
<HR SIZE="2" NOSHADE>
</FONT>
<BR>


<A NAME="1008312"> </A><FONT FACE="Arial, Helvetica, sans-serif" SIZE="2"><zparagraph>You construct a regular expression in one of two ways:</zparagraph>
</FONT>
<P>
<ul>
<A NAME="1008313"> </A>
<FONT FACE="Arial, Helvetica, sans-serif" SIZE="2">
<B>  <li></B>
<zsmartlist1>Using a regular expression literal, as follows:</zsmartlist1>
</FONT>
<P><A NAME="1008314"></A><FONT FACE="courier, couriernew, monospaced size" SIZE="2">
<zcodeline>re = /ab+c/
</zcodeline>
</FONT>
<P>  <dl>
     <DT> <A NAME="1008315"> </A>
<FONT FACE="Arial, Helvetica, sans-serif" SIZE="2">
<zparaindent1>Regular expression literals provide compilation of the regular expression when the script is evaluated. When the regular expression will remain constant, use this for better performance. </zparaindent1>
</FONT>
<P>  </dl>
<A NAME="1008316"> </A>
<FONT FACE="Arial, Helvetica, sans-serif" SIZE="2">
<B>  <li></B>
<zsmartlist1>Calling the constructor function of the <FONT FACE="courier, couriernew, monospaced size">RegExp</FONT> object, as follows:</zsmartlist1>
</FONT>
<P><A NAME="1008317"></A><FONT FACE="courier, couriernew, monospaced size" SIZE="2">
<zcodeline>re = new RegExp("ab+c")
</zcodeline>
</FONT>
<P>  <dl>
     <DT> <A NAME="1010687"> </A>
<FONT FACE="Arial, Helvetica, sans-serif" SIZE="2">
<zparaindent1>Using the constructor function provides runtime compilation of the regular expression. Use the constructor function when you know the regular expression pattern will be changing, or you don't know the pattern and are getting it from another source, such as user input. </zparaindent1>
</FONT>
<P>  </dl>
</ul>

<BR>
<BR>

<A NAME="1010689"> </A>
<A NAME="Writing a Regular Expression Pattern"> </A>
<FONT FACE="Arial, Helvetica, sans-serif" SIZE="4">
<zhead1>Writing a Regular Expression Pattern</zhead1>
<HR SIZE="2" NOSHADE>
</FONT>
<BR>


<A NAME="1010690"> </A><FONT FACE="Arial, Helvetica, sans-serif" SIZE="2"><zparagraph>A regular expression pattern is composed of simple characters, such as <FONT FACE="courier, couriernew, monospaced size">/abc/</FONT>, or a combination of simple and special characters, such as <FONT FACE="courier, couriernew, monospaced size">/ab*c/</FONT> or <br><FONT FACE="courier, couriernew, monospaced size">/Chapter&nbsp;(\d+)\.\d*/</FONT>. The last example includes parentheses which are used as a memory device. The match made with this part of the pattern is remembered for later use, as described in <A HREF="regexp.html#1008659"  >Using Parenthesized Substring Matches</A>.</zparagraph>
</FONT>
<P>
<P>
<BR>
<A NAME="1008325"> </A>
<A NAME="Using Simple Patterns"> </A>
<FONT FACE="Arial, Helvetica, sans-serif" SIZE="4">
<zhead2>Using Simple Patterns</zhead2>
</FONT>
<BR>
<BR>



<A NAME="1008326"> </A><FONT FACE="Arial, Helvetica, sans-serif" SIZE="2"><zparagraph>Simple patterns are constructed of characters for which you want to find a direct match. For example, the pattern <FONT FACE="courier, couriernew, monospaced size">/abc/</FONT> matches character combinations in strings only when exactly the characters 'abc' occur together and in that order. Such a match would succeed in the strings "Hi, do you know your abc's?" and "The latest airplane designs evolved from slabcraft." In both cases the match is with the substring 'abc'. There is no match in the string "Grab crab" because it does not contain the substring 'abc'.</zparagraph>
</FONT>
<P>
<P>
<BR>
<A NAME="1008327"> </A>
<A NAME="Using Special Characters"> </A>
<FONT FACE="Arial, Helvetica, sans-serif" SIZE="4">
<zhead2>Using Special Characters</zhead2>
</FONT>
<BR>
<BR>



<A NAME="1008328"> </A><FONT FACE="Arial, Helvetica, sans-serif" SIZE="2"><zparagraph>When the search for a match requires something more than a direct match, such as finding one or more b's, or finding whitespace, the pattern includes special characters. For example, the pattern <FONT FACE="courier, couriernew, monospaced size">/ab*c/</FONT> matches any character combination in which a single 'a' is followed by zero or more 'b's (<FONT FACE="courier, couriernew, monospaced size">*</FONT> means 0 or more occurrences of the preceding item) and then immediately followed by 'c'. In the string "cbbabbbbcdebc," the pattern matches the substring 'abbbbc'.</zparagraph>
</FONT>
<P>

<A NAME="1008332"> </A><FONT FACE="Arial, Helvetica, sans-serif" SIZE="2"><zparagraph>The following table provides a complete list and description of the special characters that can be used in regular expressions.</zparagraph>
</FONT>
<P>

<P>
<A NAME="1009645"> </A>
<FONT FACE="Arial, Helvetica, sans-serif" SIZE="2">
<BR>
<P>
<TABLE WIDTH="90%" BORDER="1" CELLPADDING="5" CELLSPACING="0">
  <CAPTION></CAPTION><P><FONT FACE=""><B>
<A NAME="1013218"> </A>
<A NAME="Special characters in regular expressions. &nbsp;"> </A>
<ALIGN="LEFT">
<FONT FACE="Arial, Helvetica, sans-serif" SIZE="2">
<B>
<ztablecaption>Table 4.1&#32;&nbsp&nbsp Special characters in regular expressions. &nbsp;</ztablecaption>
</B>
</FONT>
</B></FONT>
<BR>
<BR>
  <TR BGCOLOR="#CCCCCC" ALIGN=LEFT VALIGN=TOP>
    <TH VALIGN=TOP ALIGN=LEFT><A NAME="1013222"> </A>
<P ALIGN="LEFT">
<FONT FACE="Arial, Helvetica, sans-serif" SIZE="2">
<B>
<ztablehead>Character</ztablehead>
</B>
</FONT>
</TH>
    <TH VALIGN=TOP ALIGN=LEFT><A NAME="1013224"> </A>
<P ALIGN="LEFT">
<FONT FACE="Arial, Helvetica, sans-serif" SIZE="2">
<B>
<ztablehead>Meaning</ztablehead>
</B>
</FONT>
</TH>
  </DIV></TR>
  <TR>
    <TD VALIGN=TOP><A NAME="1013226"></A><FONT FACE="courier, couriernew, monospaced size" SIZE="2">
<zcodeline>\
</zcodeline>
</FONT>
<P>&nbsp;</TD>
    <TD VALIGN=TOP>
<P>
<A NAME="1013228"> </A>
<FONT FACE="Arial, Helvetica, sans-serif" SIZE="2">
<ztabletext>Either of the following:</ztabletext>
</FONT><ul>
<A NAME="1013229"> </A>
<FONT FACE="Arial, Helvetica, sans-serif" SIZE="2">
<B>  <li></B>
<zsmartlist1>For characters that are usually treated literally, indicates that the next character is special and not to be interpreted literally.</zsmartlist1>
</FONT>
<P>  <dl>
     <DT> <A NAME="1013230"> </A>
<FONT FACE="Arial, Helvetica, sans-serif" SIZE="2">
<zparaindent1>For example, <FONT FACE="courier, couriernew, monospaced size">/b/</FONT> matches the character 'b'. By placing a backslash in front of b, that is by using <FONT FACE="courier, couriernew, monospaced size">/\b/</FONT>, the character becomes special to mean match a word boundary.</zparaindent1>
</FONT>
<P>  </dl>
<A NAME="1013231"> </A>
<FONT FACE="Arial, Helvetica, sans-serif" SIZE="2">
<B>  <li></B>
<zsmartlist1>For characters that are usually treated specially, indicates that the next character is not special and should be interpreted literally.</zsmartlist1>
</FONT>
<P>  <dl>
     <DT> <A NAME="1013232"> </A>
<FONT FACE="Arial, Helvetica, sans-serif" SIZE="2">
<zparaindent1>For example, <FONT FACE="courier, couriernew, monospaced size">*</FONT> is a special character that means 0 or more occurrences of the preceding item should be matched; for example, <FONT FACE="courier, couriernew, monospaced size">/a*/</FONT> means match 0 or more a's<FONT FACE="courier, couriernew, monospaced size">.</FONT> To match <FONT FACE="courier, couriernew, monospaced size">*</FONT> literally, precede the it with a backslash; for example, <FONT FACE="courier, couriernew, monospaced size">/a\*/</FONT> matches 'a*'.</zparaindent1>
</FONT>
<P>  </dl>
</ul>
&nbsp;</TD>
  </TR>
  <TR>
    <TD VALIGN=TOP><A NAME="1013234"></A><FONT FACE="courier, couriernew, monospaced size" SIZE="2">
<zcodeline>^
</zcodeline>
</FONT>
<P>&nbsp;</TD>
    <TD VALIGN=TOP>
<P>
<A NAME="1013236"> </A>
<FONT FACE="Arial, Helvetica, sans-serif" SIZE="2">
<ztabletext>Matches beginning of input. If the multiline flag is set to true, also matches immediately after a line break character.</ztabletext>
</FONT>
<P>
<A NAME="1013237"> </A>
<FONT FACE="Arial, Helvetica, sans-serif" SIZE="2">
<ztabletext></ztabletext>
</FONT>
<P>
<A NAME="1013238"> </A>
<FONT FACE="Arial, Helvetica, sans-serif" SIZE="2">
<ztabletext>For example, <FONT FACE="courier, couriernew, monospaced size">/^A/</FONT> does not match the 'A' in "an A", but does match the first 'A' in "An A".</ztabletext>
</FONT>&nbsp;</TD>
  </TR>
  <TR>
    <TD VALIGN=TOP><A NAME="1013240"></A><FONT FACE="courier, couriernew, monospaced size" SIZE="2">
<zcodeline>$
</zcodeline>
</FONT>
<P>&nbsp;</TD>
    <TD VALIGN=TOP>
<P>
<A NAME="1013242"> </A>
<FONT FACE="Arial, Helvetica, sans-serif" SIZE="2">
<ztabletext>Matches end of input. If the multiline flag is set to true, also matches immediately before a line break character.</ztabletext>
</FONT>
<P>
<A NAME="1013243"> </A>
<FONT FACE="Arial, Helvetica, sans-serif" SIZE="2">
<ztabletext></ztabletext>
</FONT>
<P>
<A NAME="1013244"> </A>
<FONT FACE="Arial, Helvetica, sans-serif" SIZE="2">
<ztabletext>For example, <FONT FACE="courier, couriernew, monospaced size">/t$/</FONT> does not match the 't' in "eater", but does match it in "eat".</ztabletext>
</FONT>&nbsp;</TD>
  </TR>
  <TR>
    <TD VALIGN=TOP><A NAME="1013246"></A><FONT FACE="courier, couriernew, monospaced size" SIZE="2">
<zcodeline>*
</zcodeline>
</FONT>
<P>&nbsp;</TD>
    <TD VALIGN=TOP>
<P>
<A NAME="1013248"> </A>
<FONT FACE="Arial, Helvetica, sans-serif" SIZE="2">
<ztabletext>Matches the preceding character 0 or more times.</ztabletext>
</FONT>
<P>
<A NAME="1013249"> </A>
<FONT FACE="Arial, Helvetica, sans-serif" SIZE="2">
<ztabletext></ztabletext>
</FONT>
<P>
<A NAME="1013250"> </A>
<FONT FACE="Arial, Helvetica, sans-serif" SIZE="2">
<ztabletext>For example, <FONT FACE="courier, couriernew, monospaced size">/bo*/</FONT> matches 'boooo' in "A ghost booooed" and 'b' in "A bird warbled", but nothing in "A goat grunted".</ztabletext>
</FONT>&nbsp;</TD>
  </TR>
  <TR>
    <TD VALIGN=TOP><A NAME="1013252"></A><FONT FACE="courier, couriernew, monospaced size" SIZE="2">
<zcodeline>+
</zcodeline>
</FONT>
<P>&nbsp;</TD>
    <TD VALIGN=TOP>
<P>
<A NAME="1013254"> </A>
<FONT FACE="Arial, Helvetica, sans-serif" SIZE="2">
<ztabletext>Matches the preceding character 1 or more times. Equivalent to <FONT FACE="courier, couriernew, monospaced size">{1,}</FONT>.</ztabletext>
</FONT>
<P>
<A NAME="1013255"> </A>
<FONT FACE="Arial, Helvetica, sans-serif" SIZE="2">
<ztabletext></ztabletext>
</FONT>
<P>
<A NAME="1013256"> </A>
<FONT FACE="Arial, Helvetica, sans-serif" SIZE="2">
<ztabletext>For example, <FONT FACE="courier, couriernew, monospaced size">/a+/</FONT> matches the 'a' in "candy" and all the a's in "caaaaaaandy".</ztabletext>
</FONT>&nbsp;</TD>
  </TR>
  <TR>
    <TD VALIGN=TOP><A NAME="1013259"></A><FONT FACE="courier, couriernew, monospaced size" SIZE="2">
<zcodeline>?
</zcodeline>
</FONT>
<P>&nbsp;</TD>
    <TD VALIGN=TOP>
<P>
<A NAME="1013261"> </A>
<FONT FACE="Arial, Helvetica, sans-serif" SIZE="2">
<ztabletext>Matches the preceding character 0 or 1 time.</ztabletext>
</FONT>
<P>
<A NAME="1013262"> </A>
<FONT FACE="Arial, Helvetica, sans-serif" SIZE="2">
<ztabletext></ztabletext>
</FONT>
<P>
<A NAME="1013263"> </A>
<FONT FACE="Arial, Helvetica, sans-serif" SIZE="2">
<ztabletext>For example, <FONT FACE="courier, couriernew, monospaced size">/e?le?/</FONT> matches the 'el' in "angel" and the 'le' in "angle."</ztabletext>
</FONT>
<P>
<A NAME="1013264"> </A>
<FONT FACE="Arial, Helvetica, sans-serif" SIZE="2">
<ztabletext></ztabletext>
</FONT>
<P>
<A NAME="1013265"> </A>
<FONT FACE="Arial, Helvetica, sans-serif" SIZE="2">
<ztabletext>If used immediately after any of the quantifiers <FONT FACE="courier, couriernew, monospaced size">*</FONT>, <FONT FACE="courier, couriernew, monospaced size">+</FONT>, <FONT FACE="courier, couriernew, monospaced size">?</FONT>, or <FONT FACE="courier, couriernew, monospaced size">{}</FONT>, makes the quantifier non-greedy (matching the minimum number of times), as opposed to the default, which is greedy (matching the maximum number of times). </ztabletext>
</FONT>
<P>
<A NAME="1013266"> </A>
<FONT FACE="Arial, Helvetica, sans-serif" SIZE="2">
<ztabletext>Also used in lookahead assertions, described under x(?=y)<FONT FACE="courier, couriernew, monospaced size"> </FONT>and<FONT FACE="courier, couriernew, monospaced size"> </FONT>x(?!y)<FONT FACE="courier, couriernew, monospaced size"> </FONT>in this table.</ztabletext>
</FONT>&nbsp;</TD>
  </TR>
  <TR>
    <TD VALIGN=TOP><A NAME="1013268"></A><FONT FACE="courier, couriernew, monospaced size" SIZE="2">
<zcodeline>.
</zcodeline>
</FONT>
<P>&nbsp;</TD>
    <TD VALIGN=TOP>
<P>
<A NAME="1013270"> </A>
<FONT FACE="Arial, Helvetica, sans-serif" SIZE="2">
<ztabletext>(The decimal point) matches any single character except the newline character.</ztabletext>
</FONT>
<P>
<A NAME="1013271"> </A>
<FONT FACE="Arial, Helvetica, sans-serif" SIZE="2">
<ztabletext></ztabletext>
</FONT>
<P>
<A NAME="1013272"> </A>
<FONT FACE="Arial, Helvetica, sans-serif" SIZE="2">
<ztabletext>For example, <FONT FACE="courier, couriernew, monospaced size">/.n/</FONT> matches 'an' and 'on' in "nay, an apple is on the tree", but not 'nay'.</ztabletext>
</FONT>&nbsp;</TD>
  </TR>
  <TR>
    <TD VALIGN=TOP><A NAME="1013274"></A><FONT FACE="courier, couriernew, monospaced size" SIZE="2">
<zcodeline>(x)
</zcodeline>
</FONT>
<P>&nbsp;</TD>
    <TD VALIGN=TOP>
<P>
<A NAME="1013277"> </A>
<FONT FACE="Arial, Helvetica, sans-serif" SIZE="2">
<ztabletext>Matches 'x' and remembers the match. These are called capturing parentheses.</ztabletext>
</FONT>
<P>
<A NAME="1013278"> </A>
<FONT FACE="Arial, Helvetica, sans-serif" SIZE="2">
<ztabletext></ztabletext>
</FONT>
<P>
<A NAME="1013279"> </A>
<FONT FACE="Arial, Helvetica, sans-serif" SIZE="2">
<ztabletext>For example, <FONT FACE="courier, couriernew, monospaced size">/(foo)/</FONT> matches and remembers 'foo' in "foo bar." The matched substring can be recalled from the resulting array's elements <FONT FACE="courier, couriernew, monospaced size">[1]</FONT>, ..., <FONT FACE="courier, couriernew, monospaced size">[n]</FONT>.</ztabletext>
</FONT>&nbsp;</TD>
  </TR>
  <TR>
    <TD VALIGN=TOP><A NAME="1013282"></A><FONT FACE="courier, couriernew, monospaced size" SIZE="2">
<zcodeline>(?:x)
</zcodeline>
</FONT>
<P>&nbsp;</TD>
    <TD VALIGN=TOP>
<P>
<A NAME="1013285"> </A>
<FONT FACE="Arial, Helvetica, sans-serif" SIZE="2">
<ztabletext>Matches 'x' but does not remember the match. These are called non-capturing parentheses. The matched substring can not be recalled from the resulting array's elements <FONT FACE="courier, couriernew, monospaced size">[1]</FONT>, ..., <FONT FACE="courier, couriernew, monospaced size">[n]</FONT>.</ztabletext>
</FONT>&nbsp;</TD>
  </TR>
  <TR>
    <TD VALIGN=TOP><A NAME="1013288"></A><FONT FACE="courier, couriernew, monospaced size" SIZE="2">
<zcodeline>x(?=y)
</zcodeline>
</FONT>
<P>&nbsp;</TD>
    <TD VALIGN=TOP>
<P>
<A NAME="1013290"> </A>
<FONT FACE="Arial, Helvetica, sans-serif" SIZE="2">
<ztabletext>Matches 'x' only if 'x' is followed by 'y'. For example, <FONT FACE="courier, couriernew, monospaced size">/Jack(?=Sprat)/</FONT> matches 'Jack' only if it is followed by 'Sprat'. /<FONT FACE="courier, couriernew, monospaced size">Jack(?=Sprat|Frost)/</FONT>matches 'Jack' only if it is followed by 'Sprat' or 'Frost'. However, neither 'Sprat' nor 'Frost' is part of the match results.</ztabletext>
</FONT>&nbsp;</TD>
  </TR>
  <TR>
    <TD VALIGN=TOP><A NAME="1013293"></A><FONT FACE="courier, couriernew, monospaced size" SIZE="2">
<zcodeline>x(?!y)
</zcodeline>
</FONT>
<P>&nbsp;</TD>
    <TD VALIGN=TOP>
<P>
<A NAME="1013295"> </A>
<FONT FACE="Arial, Helvetica, sans-serif" SIZE="2">
<ztabletext>Matches 'x' only if 'x' is not followed by 'y'. For example, <FONT FACE="courier, couriernew, monospaced size">/\d+(?!\.)/</FONT> matches a number only if it is not followed by a decimal point. The regular expression <FONT FACE="courier, couriernew, monospaced size">/\d+(?!\.)/.exec("3.141")</FONT> matches 141 but not 3.141.</ztabletext>
</FONT>&nbsp;</TD>
  </TR>
  <TR>
    <TD VALIGN=TOP><A NAME="1013297"></A><FONT FACE="courier, couriernew, monospaced size" SIZE="2">
<zcodeline>x|y
</zcodeline>
</FONT>
<P>&nbsp;</TD>
    <TD VALIGN=TOP>
<P>
<A NAME="1013299"> </A>
<FONT FACE="Arial, Helvetica, sans-serif" SIZE="2">
<ztabletext>Matches either 'x' or 'y'.</ztabletext>
</FONT>
<P>
<A NAME="1013300"> </A>
<FONT FACE="Arial, Helvetica, sans-serif" SIZE="2">
<ztabletext></ztabletext>
</FONT>
<P>
<A NAME="1013301"> </A>
<FONT FACE="Arial, Helvetica, sans-serif" SIZE="2">
<ztabletext>For example, <FONT FACE="courier, couriernew, monospaced size">/green|red/</FONT> matches 'green' in "green apple" and 'red' in "red apple."</ztabletext>
</FONT>&nbsp;</TD>
  </TR>
  <TR>
    <TD VALIGN=TOP><A NAME="1013303"></A><FONT FACE="courier, couriernew, monospaced size" SIZE="2">
<zcodeline>{n}
</zcodeline>
</FONT>
<P>&nbsp;</TD>
    <TD VALIGN=TOP>
<P>
<A NAME="1013305"> </A>
<FONT FACE="Arial, Helvetica, sans-serif" SIZE="2">
<ztabletext>Where <FONT FACE="courier, couriernew, monospaced size">n</FONT> is a positive integer. Matches exactly <FONT FACE="courier, couriernew, monospaced size">n</FONT> occurrences of the preceding character.</ztabletext>
</FONT>
<P>
<A NAME="1013306"> </A>
<FONT FACE="Arial, Helvetica, sans-serif" SIZE="2">
<ztabletext></ztabletext>
</FONT>
<P>
<A NAME="1013307"> </A>
<FONT FACE="Arial, Helvetica, sans-serif" SIZE="2">
<ztabletext>For example, <FONT FACE="courier, couriernew, monospaced size">/a{2}/</FONT> doesn't match the 'a' in "candy," but it matches all of the a's in "caandy," and the first two a's in "caaandy."</ztabletext>
</FONT>&nbsp;</TD>
  </TR>
  <TR>
    <TD VALIGN=TOP><A NAME="1013309"></A><FONT FACE="courier, couriernew, monospaced size" SIZE="2">
<zcodeline>{n,}
</zcodeline>
</FONT>
<P>&nbsp;</TD>
    <TD VALIGN=TOP>
<P>
<A NAME="1013311"> </A>
<FONT FACE="Arial, Helvetica, sans-serif" SIZE="2">
<ztabletext>Where <FONT FACE="courier, couriernew, monospaced size">n</FONT> is a positive integer. Matches at least <FONT FACE="courier, couriernew, monospaced size">n</FONT> occurrences of the preceding character.</ztabletext>
</FONT>
<P>
<A NAME="1013312"> </A>
<FONT FACE="Arial, Helvetica, sans-serif" SIZE="2">
<ztabletext></ztabletext>
</FONT>
<P>
<A NAME="1013313"> </A>
<FONT FACE="Arial, Helvetica, sans-serif" SIZE="2">
<ztabletext>For example, <FONT FACE="courier, couriernew, monospaced size">/a{2,}</FONT> doesn't match the 'a' in "candy", but matches all of the a's in "caandy" and in "caaaaaaandy."</ztabletext>
</FONT>&nbsp;</TD>
  </TR>
  <TR>
    <TD VALIGN=TOP><A NAME="1013315"></A><FONT FACE="courier, couriernew, monospaced size" SIZE="2">
<zcodeline>{n,m}
</zcodeline>
</FONT>
<P>&nbsp;</TD>
    <TD VALIGN=TOP>
<P>
<A NAME="1013317"> </A>
<FONT FACE="Arial, Helvetica, sans-serif" SIZE="2">
<ztabletext>Where <FONT FACE="courier, couriernew, monospaced size">n</FONT> and <FONT FACE="courier, couriernew, monospaced size">m</FONT> are positive integers. Matches at least <FONT FACE="courier, couriernew, monospaced size">n</FONT> and at most <FONT FACE="courier, couriernew, monospaced size">m</FONT> occurrences of the preceding character.</ztabletext>
</FONT>
<P>
<A NAME="1013318"> </A>
<FONT FACE="Arial, Helvetica, sans-serif" SIZE="2">
<ztabletext></ztabletext>
</FONT>
<P>
<A NAME="1013319"> </A>
<FONT FACE="Arial, Helvetica, sans-serif" SIZE="2">
<ztabletext>For example, <FONT FACE="courier, couriernew, monospaced size">/a{1,3}/</FONT> matches nothing in "cndy", the 'a' in "candy," the first two a's in "caandy," and the first three a's in "caaaaaaandy" Notice that when matching "caaaaaaandy", the match is "aaa", even though the original string had more a's in it.</ztabletext>
</FONT>&nbsp;</TD>
  </TR>
  <TR>
    <TD VALIGN=TOP><A NAME="1013321"></A><FONT FACE="courier, couriernew, monospaced size" SIZE="2">
<zcodeline>[xyz]
</zcodeline>
</FONT>
<P>&nbsp;</TD>
    <TD VALIGN=TOP>
<P>
<A NAME="1013323"> </A>
<FONT FACE="Arial, Helvetica, sans-serif" SIZE="2">
<ztabletext>A character set. Matches any one of the enclosed characters. You can specify a range of characters by using a hyphen.</ztabletext>
</FONT>
<P>
<A NAME="1013324"> </A>
<FONT FACE="Arial, Helvetica, sans-serif" SIZE="2">
<ztabletext></ztabletext>
</FONT>
<P>
<A NAME="1013325"> </A>
<FONT FACE="Arial, Helvetica, sans-serif" SIZE="2">
<ztabletext>For example, <FONT FACE="courier, couriernew, monospaced size">[abcd]</FONT> is the same as <FONT FACE="courier, couriernew, monospaced size">[a-d]</FONT>. They match the 'b' in "brisket" and the 'c' in "ache".</ztabletext>
</FONT>&nbsp;</TD>
  </TR>
  <TR>
    <TD VALIGN=TOP><A NAME="1013327"></A><FONT FACE="courier, couriernew, monospaced size" SIZE="2">
<zcodeline>[^xyz]
</zcodeline>
</FONT>
<P>&nbsp;</TD>
    <TD VALIGN=TOP>
<P>
<A NAME="1013329"> </A>
<FONT FACE="Arial, Helvetica, sans-serif" SIZE="2">
<ztabletext>A negated or complemented character set. That is, it matches anything that is not enclosed in the brackets. You can specify a range of characters by using a hyphen.</ztabletext>
</FONT>
<P>
<A NAME="1013330"> </A>
<FONT FACE="Arial, Helvetica, sans-serif" SIZE="2">
<ztabletext></ztabletext>
</FONT>
<P>
<A NAME="1013331"> </A>
<FONT FACE="Arial, Helvetica, sans-serif" SIZE="2">
<ztabletext>For example, <FONT FACE="courier, couriernew, monospaced size">[^abc]</FONT> is the same as <FONT FACE="courier, couriernew, monospaced size">[^a-c]</FONT>. They initially match 'r' in "brisket" and 'h' in "chop."</ztabletext>
</FONT>&nbsp;</TD>
  </TR>
  <TR>
    <TD VALIGN=TOP><A NAME="1013333"></A><FONT FACE="courier, couriernew, monospaced size" SIZE="2">
<zcodeline>[\b]
</zcodeline>
</FONT>
<P>&nbsp;</TD>
    <TD VALIGN=TOP>
<P>
<A NAME="1013335"> </A>
<FONT FACE="Arial, Helvetica, sans-serif" SIZE="2">
<ztabletext>Matches a backspace. (Not to be confused with <FONT FACE="courier, couriernew, monospaced size">\b</FONT>.)</ztabletext>
</FONT>&nbsp;</TD>
  </TR>
  <TR>
    <TD VALIGN=TOP><A NAME="1013337"></A><FONT FACE="courier, couriernew, monospaced size" SIZE="2">
<zcodeline>\b
</zcodeline>
</FONT>
<P>&nbsp;</TD>
    <TD VALIGN=TOP>
<P>
<A NAME="1013339"> </A>
<FONT FACE="Arial, Helvetica, sans-serif" SIZE="2">
<ztabletext>Matches a word boundary, such as a space or a newline character. (Not to be confused with <FONT FACE="courier, couriernew, monospaced size">[\b]</FONT>.)</ztabletext>
</FONT>
<P>
<A NAME="1013340"> </A>
<FONT FACE="Arial, Helvetica, sans-serif" SIZE="2">
<ztabletext></ztabletext>
</FONT>
<P>
<A NAME="1013341"> </A>
<FONT FACE="Arial, Helvetica, sans-serif" SIZE="2">
<ztabletext>For example, <FONT FACE="courier, couriernew, monospaced size">/\bn\w/</FONT> matches the 'no' in "noonday";<FONT FACE="courier, couriernew, monospaced size">/\wy\b/</FONT> matches the 'ly' in "possibly yesterday."</ztabletext>
</FONT>&nbsp;</TD>
  </TR>
  <TR>
    <TD VALIGN=TOP><A NAME="1013343"></A><FONT FACE="courier, couriernew, monospaced size" SIZE="2">
<zcodeline>\B
</zcodeline>
</FONT>
<P>&nbsp;</TD>
    <TD VALIGN=TOP>
<P>
<A NAME="1013345"> </A>
<FONT FACE="Arial, Helvetica, sans-serif" SIZE="2">
<ztabletext>Matches a non-word boundary.</ztabletext>
</FONT>
<P>
<A NAME="1013346"> </A>
<FONT FACE="Arial, Helvetica, sans-serif" SIZE="2">
<ztabletext></ztabletext>
</FONT>
<P>
<A NAME="1013347"> </A>
<FONT FACE="Arial, Helvetica, sans-serif" SIZE="2">
<ztabletext>For example, <FONT FACE="courier, couriernew, monospaced size">/\w\Bn/</FONT> matches 'on' in "noonday", and <FONT FACE="courier, couriernew, monospaced size">/y\B\w/</FONT> matches 'ye' in "possibly yesterday."</ztabletext>
</FONT>&nbsp;</TD>
  </TR>
  <TR>
    <TD VALIGN=TOP><A NAME="1013349"></A><FONT FACE="courier, couriernew, monospaced size" SIZE="2">
<zcodeline>\c<I>X
</I></zcodeline>
</FONT>
<P>&nbsp;</TD>
    <TD VALIGN=TOP>
<P>
<A NAME="1013351"> </A>
<FONT FACE="Arial, Helvetica, sans-serif" SIZE="2">
<ztabletext>Where <I>X</I> is a control character. Matches a control character in a string.</ztabletext>
</FONT>
<P>
<A NAME="1013352"> </A>
<FONT FACE="Arial, Helvetica, sans-serif" SIZE="2">
<ztabletext></ztabletext>
</FONT>
<P>
<A NAME="1013353"> </A>
<FONT FACE="Arial, Helvetica, sans-serif" SIZE="2">
<ztabletext>For example, <FONT FACE="courier, couriernew, monospaced size">/\cM/</FONT> matches control-M in a string.</ztabletext>
</FONT>&nbsp;</TD>
  </TR>
  <TR>
    <TD VALIGN=TOP><A NAME="1013355"></A><FONT FACE="courier, couriernew, monospaced size" SIZE="2">
<zcodeline>\d
</zcodeline>
</FONT>
<P>&nbsp;</TD>
    <TD VALIGN=TOP>
<P>
<A NAME="1013357"> </A>
<FONT FACE="Arial, Helvetica, sans-serif" SIZE="2">
<ztabletext>Matches a digit character. Equivalent to <FONT FACE="courier, couriernew, monospaced size">[0-9]</FONT>.</ztabletext>
</FONT>
<P>
<A NAME="1013358"> </A>
<FONT FACE="Arial, Helvetica, sans-serif" SIZE="2">
<ztabletext></ztabletext>
</FONT>
<P>
<A NAME="1013359"> </A>
<FONT FACE="Arial, Helvetica, sans-serif" SIZE="2">
<ztabletext>For example, <FONT FACE="courier, couriernew, monospaced size">/\d/</FONT> or <FONT FACE="courier, couriernew, monospaced size">/[0-9]/</FONT> matches '2' in "B2 is the suite number."</ztabletext>
</FONT>&nbsp;</TD>
  </TR>
  <TR>
    <TD VALIGN=TOP><A NAME="1013361"></A><FONT FACE="courier, couriernew, monospaced size" SIZE="2">
<zcodeline>\D
</zcodeline>
</FONT>
<P>&nbsp;</TD>
    <TD VALIGN=TOP>
<P>
<A NAME="1013363"> </A>
<FONT FACE="Arial, Helvetica, sans-serif" SIZE="2">
<ztabletext>Matches any non-digit character. Equivalent to <FONT FACE="courier, couriernew, monospaced size">[^0-9]</FONT>.</ztabletext>
</FONT>
<P>
<A NAME="1013364"> </A>
<FONT FACE="Arial, Helvetica, sans-serif" SIZE="2">
<ztabletext></ztabletext>
</FONT>
<P>
<A NAME="1013365"> </A>
<FONT FACE="Arial, Helvetica, sans-serif" SIZE="2">
<ztabletext>For example, <FONT FACE="courier, couriernew, monospaced size">/\D/</FONT> or <FONT FACE="courier, couriernew, monospaced size">/[^0-9]/</FONT> matches 'B' in "B2 is the suite number."</ztabletext>
</FONT>&nbsp;</TD>
  </TR>
  <TR>
    <TD VALIGN=TOP><A NAME="1013367"></A><FONT FACE="courier, couriernew, monospaced size" SIZE="2">
<zcodeline>\f
</zcodeline>
</FONT>
<P>&nbsp;</TD>
    <TD VALIGN=TOP>
<P>
<A NAME="1013369"> </A>
<FONT FACE="Arial, Helvetica, sans-serif" SIZE="2">
<ztabletext>Matches a form-feed.</ztabletext>
</FONT>&nbsp;</TD>
  </TR>
  <TR>
    <TD VALIGN=TOP><A NAME="1013371"></A><FONT FACE="courier, couriernew, monospaced size" SIZE="2">
<zcodeline>\n
</zcodeline>
</FONT>
<P>&nbsp;</TD>
    <TD VALIGN=TOP>
<P>
<A NAME="1013373"> </A>
<FONT FACE="Arial, Helvetica, sans-serif" SIZE="2">
<ztabletext>Matches a linefeed.</ztabletext>
</FONT>&nbsp;</TD>
  </TR>
  <TR>
    <TD VALIGN=TOP><A NAME="1013375"></A><FONT FACE="courier, couriernew, monospaced size" SIZE="2">
<zcodeline>\r
</zcodeline>
</FONT>
<P>&nbsp;</TD>
    <TD VALIGN=TOP>
<P>
<A NAME="1013377"> </A>
<FONT FACE="Arial, Helvetica, sans-serif" SIZE="2">
<ztabletext>Matches a carriage return.</ztabletext>
</FONT>&nbsp;</TD>
  </TR>
  <TR>
    <TD VALIGN=TOP><A NAME="1013379"></A><FONT FACE="courier, couriernew, monospaced size" SIZE="2">
<zcodeline>\s
</zcodeline>
</FONT>
<P>&nbsp;</TD>
    <TD VALIGN=TOP>
<P>
<A NAME="1013381"> </A>
<FONT FACE="Arial, Helvetica, sans-serif" SIZE="2">
<ztabletext>Matches a single white space character, including space, tab, form feed, line feed. Equivalent to <FONT FACE="courier, couriernew, monospaced size">[ \f\n\r\t\v\u00A0\u2028\u2029]</FONT>.</ztabletext>
</FONT>
<P>
<A NAME="1013382"> </A>
<FONT FACE="Arial, Helvetica, sans-serif" SIZE="2">
<ztabletext></ztabletext>
</FONT>
<P>
<A NAME="1013383"> </A>
<FONT FACE="Arial, Helvetica, sans-serif" SIZE="2">
<ztabletext>For example, <FONT FACE="courier, couriernew, monospaced size">/\s\w*/</FONT> matches ' bar' in "foo bar."</ztabletext>
</FONT>&nbsp;</TD>
  </TR>
  <TR>
    <TD VALIGN=TOP><A NAME="1013385"></A><FONT FACE="courier, couriernew, monospaced size" SIZE="2">
<zcodeline>\S
</zcodeline>
</FONT>
<P>&nbsp;</TD>
    <TD VALIGN=TOP>
<P>
<A NAME="1013387"> </A>
<FONT FACE="Arial, Helvetica, sans-serif" SIZE="2">
<ztabletext>Matches a single character other than white space. Equivalent to <br><FONT FACE="courier, couriernew, monospaced size">[ ^\f\n\r\t\v\u00A0\u2028\u2029]</FONT>.</ztabletext>
</FONT>
<P>
<A NAME="1013388"> </A>
<FONT FACE="Arial, Helvetica, sans-serif" SIZE="2">
<ztabletext></ztabletext>
</FONT>
<P>
<A NAME="1013389"> </A>
<FONT FACE="Arial, Helvetica, sans-serif" SIZE="2">
<ztabletext>For example, <FONT FACE="courier, couriernew, monospaced size">/\S\w*/</FONT> matches 'foo' in "foo bar."</ztabletext>
</FONT>&nbsp;</TD>
  </TR>
  <TR>
    <TD VALIGN=TOP><A NAME="1013391"></A><FONT FACE="courier, couriernew, monospaced size" SIZE="2">
<zcodeline>\t
</zcodeline>
</FONT>
<P>&nbsp;</TD>
    <TD VALIGN=TOP>
<P>
<A NAME="1013393"> </A>
<FONT FACE="Arial, Helvetica, sans-serif" SIZE="2">
<ztabletext>Matches a tab.</ztabletext>
</FONT>&nbsp;</TD>
  </TR>
  <TR>
    <TD VALIGN=TOP><A NAME="1013395"></A><FONT FACE="courier, couriernew, monospaced size" SIZE="2">
<zcodeline>\v
</zcodeline>
</FONT>
<P>&nbsp;</TD>
    <TD VALIGN=TOP>
<P>
<A NAME="1013397"> </A>
<FONT FACE="Arial, Helvetica, sans-serif" SIZE="2">
<ztabletext>Matches a vertical tab.</ztabletext>
</FONT>&nbsp;</TD>
  </TR>
  <TR>
    <TD VALIGN=TOP><A NAME="1013399"></A><FONT FACE="courier, couriernew, monospaced size" SIZE="2">
<zcodeline>\w
</zcodeline>
</FONT>
<P>&nbsp;</TD>
    <TD VALIGN=TOP>
<P>
<A NAME="1013401"> </A>
<FONT FACE="Arial, Helvetica, sans-serif" SIZE="2">
<ztabletext>Matches any alphanumeric character including the underscore. Equivalent to <FONT FACE="courier, couriernew, monospaced size">[A-Za-z0-9_]</FONT>.</ztabletext>
</FONT>
<P>
<A NAME="1013402"> </A>
<FONT FACE="Arial, Helvetica, sans-serif" SIZE="2">
<ztabletext></ztabletext>
</FONT>
<P>
<A NAME="1013403"> </A>
<FONT FACE="Arial, Helvetica, sans-serif" SIZE="2">
<ztabletext>For example, <FONT FACE="courier, couriernew, monospaced size">/\w/</FONT> matches 'a' in "apple," '5' in "$5.28," and '3' in "3D."</ztabletext>
</FONT>&nbsp;</TD>
  </TR>
  <TR>
    <TD VALIGN=TOP><A NAME="1013405"></A><FONT FACE="courier, couriernew, monospaced size" SIZE="2">
<zcodeline>\W 
</zcodeline>
</FONT>
<P>&nbsp;</TD>
    <TD VALIGN=TOP>
<P>
<A NAME="1013407"> </A>
<FONT FACE="Arial, Helvetica, sans-serif" SIZE="2">
<ztabletext>Matches any non-word character. Equivalent to <FONT FACE="courier, couriernew, monospaced size">[^A-Za-z0-9_]</FONT>.</ztabletext>
</FONT>
<P>
<A NAME="1013408"> </A>
<FONT FACE="Arial, Helvetica, sans-serif" SIZE="2">
<ztabletext></ztabletext>
</FONT>
<P>
<A NAME="1013409"> </A>
<FONT FACE="Arial, Helvetica, sans-serif" SIZE="2">
<ztabletext>For example, <FONT FACE="courier, couriernew, monospaced size">/\W/</FONT> or <FONT FACE="courier, couriernew, monospaced size">/[^$A-Za-z0-9_]/</FONT> matches '%' in "50%."</ztabletext>
</FONT>&nbsp;</TD>
  </TR>
  <TR>
    <TD VALIGN=TOP><A NAME="1013411"></A><FONT FACE="courier, couriernew, monospaced size" SIZE="2">
<zcodeline>\<I>n
</I></zcodeline>
</FONT>
<P>&nbsp;</TD>
    <TD VALIGN=TOP>
<P>
<A NAME="1013413"> </A>
<FONT FACE="Arial, Helvetica, sans-serif" SIZE="2">
<ztabletext>Where <I>n</I> is a positive integer. A back reference to the last substring matching the <I>n</I> parenthetical in the regular expression (counting left parentheses).</ztabletext>
</FONT>
<P>
<A NAME="1013414"> </A>
<FONT FACE="Arial, Helvetica, sans-serif" SIZE="2">
<ztabletext></ztabletext>
</FONT>
<P>
<A NAME="1013415"> </A>
<FONT FACE="Arial, Helvetica, sans-serif" SIZE="2">
<ztabletext>For example, <FONT FACE="courier, couriernew, monospaced size">/apple(,)\sorange\1/</FONT> matches 'apple, orange,' in "apple, orange, cherry, peach." </ztabletext>
</FONT>&nbsp;</TD>
  </TR>
  <TR>
    <TD VALIGN=TOP><A NAME="1013421"></A><FONT FACE="courier, couriernew, monospaced size" SIZE="2">
<zcodeline>\0
</zcodeline>
</FONT>
<P>&nbsp;</TD>
    <TD VALIGN=TOP>
<P>
<A NAME="1013423"> </A>
<FONT FACE="Arial, Helvetica, sans-serif" SIZE="2">
<ztabletext>Matches a NUL character. Do not follow this with another digit.</ztabletext>
</FONT>&nbsp;</TD>
  </TR>
  <TR>
    <TD VALIGN=TOP><A NAME="1013425"></A><FONT FACE="courier, couriernew, monospaced size" SIZE="2">
<zcodeline>\xhh
</zcodeline>
</FONT>
<P>&nbsp;</TD>
    <TD VALIGN=TOP>
<P>
<A NAME="1013427"> </A>
<FONT FACE="Arial, Helvetica, sans-serif" SIZE="2">
<ztabletext>Matches the character with the code hh (two hexadecimal digits)</ztabletext>
</FONT>&nbsp;</TD>
  </TR>
  <TR>
    <TD VALIGN=TOP><A NAME="1013429"></A><FONT FACE="courier, couriernew, monospaced size" SIZE="2">
<zcodeline>\uhhhh
</zcodeline>
</FONT>
<P>&nbsp;</TD>
    <TD VALIGN=TOP>
<P>
<A NAME="1013431"> </A>
<FONT FACE="Arial, Helvetica, sans-serif" SIZE="2">
<ztabletext>Matches the character with code hhhh (four hexadecimal digits).</ztabletext>
</FONT>&nbsp;</TD>
  </TR>
</TABLE>



<P>
</FONT>
<P>

<P>
<BR>
<A NAME="1008498"> </A>
<A NAME="Using Parentheses"> </A>
<FONT FACE="Arial, Helvetica, sans-serif" SIZE="4">
<zhead2>Using Parentheses</zhead2>
</FONT>
<BR>
<BR>



<A NAME="1008499"> </A><FONT FACE="Arial, Helvetica, sans-serif" SIZE="2"><zparagraph>Parentheses around any part of the regular expression pattern cause that part of the matched substring to be remembered. Once remembered, the substring can be recalled for other use, as described in <A HREF="regexp.html#1008659"  >Using Parenthesized Substring Matches</A>.</zparagraph>
</FONT>
<P>

<A NAME="1008503"> </A><FONT FACE="Arial, Helvetica, sans-serif" SIZE="2"><zparagraph>For example, the pattern <FONT FACE="courier, couriernew, monospaced size">/Chapter&nbsp;(\d+)\.\d*/</FONT> illustrates additional escaped and special characters and indicates that part of the pattern should be remembered. It matches precisely the characters 'Chapter ' followed by one or more numeric characters (<FONT FACE="courier, couriernew, monospaced size">\d</FONT> means any numeric character and <FONT FACE="courier, couriernew, monospaced size">+</FONT> means 1 or more times), followed by a decimal point (which in itself is a special character; preceding the decimal point with \ means the pattern must look for the literal character '.'), followed by any numeric character 0 or more times (<FONT FACE="courier, couriernew, monospaced size">\d</FONT> means numeric character, <FONT FACE="courier, couriernew, monospaced size">*</FONT> means 0 or more times). In addition, parentheses are used to remember the first matched numeric characters.</zparagraph>
</FONT>
<P>

<A NAME="1008504"> </A><FONT FACE="Arial, Helvetica, sans-serif" SIZE="2"><zparagraph>This pattern is found in "Open Chapter 4.3, paragraph 6" and '4' is remembered. The pattern is not found in "Chapter 3 and 4", because that string does not have a period after the '3'.</zparagraph>
</FONT>
<P>

<A NAME="1012900"> </A><FONT FACE="Arial, Helvetica, sans-serif" SIZE="2"><zparagraph>To match a substring without causing the matched part to be remembered, within the parentheses preface the pattern with <FONT FACE="courier, couriernew, monospaced size">?:</FONT>. For example, <FONT FACE="courier, couriernew, monospaced size">(?:\d+)</FONT> matches one or numeric characters but does not remember the matched characters.</zparagraph>
</FONT>
<P>

<BR>
<BR>

<A NAME="1008506"> </A>
<A NAME="Working With Regular Expressions"> </A>
<FONT FACE="Arial, Helvetica, sans-serif" SIZE="4">
<zhead1>Working With Regular Expressions</zhead1>
<HR SIZE="2" NOSHADE>
</FONT>
<BR>


<A NAME="1008507"> </A><FONT FACE="Arial, Helvetica, sans-serif" SIZE="2"><zparagraph>Regular expressions are used with the <FONT FACE="courier, couriernew, monospaced size">RegExp</FONT> methods <FONT FACE="courier, couriernew, monospaced size">test</FONT> and <FONT FACE="courier, couriernew, monospaced size">exec</FONT> and with the <FONT FACE="courier, couriernew, monospaced size">String</FONT> methods <FONT FACE="courier, couriernew, monospaced size">match</FONT>, <FONT FACE="courier, couriernew, monospaced size">replace</FONT>, <FONT FACE="courier, couriernew, monospaced size">search</FONT>, and <FONT FACE="courier, couriernew, monospaced size">split</FONT>.These methods are explained in detail in the <A HREF="http://developer.netscape.com/docs/manuals/js/core/jsref/index.htm"><I>Core JavaScript Reference</I></A>.</zparagraph>
</FONT>
<P>

<P>
<A NAME="1012481"> </A>
<FONT FACE="Arial, Helvetica, sans-serif" SIZE="2">
<BR>
<P>
<TABLE WIDTH="90%" BORDER="1" CELLPADDING="5" CELLSPACING="0">
  <CAPTION></CAPTION><P><FONT FACE=""><B>
<A NAME="1012488"> </A>
<A NAME="Methods that use regular expressions"> </A>
<ALIGN="LEFT">
<FONT FACE="Arial, Helvetica, sans-serif" SIZE="2">
<B>
<ztablecaption>Table 4.2&#32;&nbsp&nbsp Methods that use regular expressions</ztablecaption>
</B>
</FONT>
</B></FONT>
<BR>
<BR>
  <TR BGCOLOR="#CCCCCC" ALIGN=LEFT VALIGN=TOP>
    <TH VALIGN=TOP ALIGN=LEFT><A NAME="1012492"> </A>
<P ALIGN="LEFT">
<FONT FACE="Arial, Helvetica, sans-serif" SIZE="2">
<B>
<ztablehead>Method</ztablehead>
</B>
</FONT>
</TH>
    <TH VALIGN=TOP ALIGN=LEFT><A NAME="1012494"> </A>
<P ALIGN="LEFT">
<FONT FACE="Arial, Helvetica, sans-serif" SIZE="2">
<B>
<ztablehead>Description</ztablehead>
</B>
</FONT>
</TH>
  </DIV></TR>
  <TR>
    <TD VALIGN=TOP><A NAME="1012526"></A><FONT FACE="courier, couriernew, monospaced size" SIZE="2">
<zcodeline>exec
</zcodeline>
</FONT>
<P>&nbsp;</TD>
    <TD VALIGN=TOP>
<P>
<A NAME="1012528"> </A>
<FONT FACE="Arial, Helvetica, sans-serif" SIZE="2">
<ztabletext>A <FONT FACE="courier, couriernew, monospaced size">RegExp</FONT> method that executes a search for a match in a string. It returns an array of information. </ztabletext>
</FONT>&nbsp;</TD>
  </TR>
  <TR>
    <TD VALIGN=TOP><A NAME="1012530"></A><FONT FACE="courier, couriernew, monospaced size" SIZE="2">
<zcodeline>test
</zcodeline>
</FONT>
<P>&nbsp;</TD>
    <TD VALIGN=TOP>
<P>
<A NAME="1012532"> </A>
<FONT FACE="Arial, Helvetica, sans-serif" SIZE="2">
<ztabletext>A <FONT FACE="courier, couriernew, monospaced size">RegExp</FONT> method that tests for a match in a string. It returns true or false.</ztabletext>
</FONT>&nbsp;</TD>
  </TR>
  <TR>
    <TD VALIGN=TOP><A NAME="1012534"></A><FONT FACE="courier, couriernew, monospaced size" SIZE="2">
<zcodeline>match
</zcodeline>
</FONT>
<P>&nbsp;</TD>
    <TD VALIGN=TOP>
<P>
<A NAME="1012536"> </A>
<FONT FACE="Arial, Helvetica, sans-serif" SIZE="2">
<ztabletext>A <FONT FACE="courier, couriernew, monospaced size">String</FONT> method that executes a search for a match in a string. It returns an array of information or null on a mismatch.</ztabletext>
</FONT>&nbsp;</TD>
  </TR>
  <TR>
    <TD VALIGN=TOP><A NAME="1012538"></A><FONT FACE="courier, couriernew, monospaced size" SIZE="2">
<zcodeline>search
</zcodeline>
</FONT>
<P>&nbsp;</TD>
    <TD VALIGN=TOP>
<P>
<A NAME="1012540"> </A>
<FONT FACE="Arial, Helvetica, sans-serif" SIZE="2">
<ztabletext>A <FONT FACE="courier, couriernew, monospaced size">String</FONT> method that tests for a match in a string. It returns the index of the match, or -1 if the search fails.</ztabletext>
</FONT>&nbsp;</TD>
  </TR>
  <TR>
    <TD VALIGN=TOP><A NAME="1012572"></A><FONT FACE="courier, couriernew, monospaced size" SIZE="2">
<zcodeline>replace
</zcodeline>
</FONT>
<P>&nbsp;</TD>
    <TD VALIGN=TOP>
<P>
<A NAME="1012574"> </A>
<FONT FACE="Arial, Helvetica, sans-serif" SIZE="2">
<ztabletext>A <FONT FACE="courier, couriernew, monospaced size">String</FONT> method that executes a search for a match in a string, and replaces the matched substring with a replacement substring.</ztabletext>
</FONT>&nbsp;</TD>
  </TR>
  <TR>
    <TD VALIGN=TOP><A NAME="1012568"></A><FONT FACE="courier, couriernew, monospaced size" SIZE="2">
<zcodeline>split
</zcodeline>
</FONT>
<P>&nbsp;</TD>
    <TD VALIGN=TOP>
<P>
<A NAME="1012570"> </A>
<FONT FACE="Arial, Helvetica, sans-serif" SIZE="2">
<ztabletext>A <FONT FACE="courier, couriernew, monospaced size">String</FONT> method that uses a regular expression or a fixed string to break a string into an array of substrings.</ztabletext>
</FONT>&nbsp;</TD>
  </TR>
</TABLE>



<P>
</FONT>
<P>


<A NAME="1008538"> </A><FONT FACE="Arial, Helvetica, sans-serif" SIZE="2"><zparagraph>When you want to know whether a pattern is found in a string, use the <FONT FACE="courier, couriernew, monospaced size">test</FONT> or <FONT FACE="courier, couriernew, monospaced size">search</FONT> method; for more information (but slower execution) use the <FONT FACE="courier, couriernew, monospaced size">exec</FONT> or <FONT FACE="courier, couriernew, monospaced size">match</FONT> methods. If you use <FONT FACE="courier, couriernew, monospaced size">exec</FONT> or <FONT FACE="courier, couriernew, monospaced size">match</FONT> and if the match succeeds, these methods return an array and update properties of the associated regular expression object and also of the predefined regular expression object, <FONT FACE="courier, couriernew, monospaced size">RegExp</FONT>. If the match fails, the <FONT FACE="courier, couriernew, monospaced size">exec</FONT> method returns <FONT FACE="courier, couriernew, monospaced size">null</FONT> (which converts to <FONT FACE="courier, couriernew, monospaced size">false</FONT>).</zparagraph>
</FONT>
<P>

<A NAME="1008539"> </A><FONT FACE="Arial, Helvetica, sans-serif" SIZE="2"><zparagraph>In the following example, the script uses the <FONT FACE="courier, couriernew, monospaced size">exec</FONT> method to find a match in a string.</zparagraph>
</FONT>
<P>
<A NAME="1008540"></A><FONT FACE="courier, couriernew, monospaced size" SIZE="2">
<zcodeline>&lt;SCRIPT LANGUAGE="JavaScript1.2"&gt;<br>
myRe=/d(b+)d/g;<br>
myArray = myRe.exec("cdbbdbsbz");<br>
&lt;/SCRIPT&gt;
</zcodeline>
</FONT>
<P>
<A NAME="1008541"> </A><FONT FACE="Arial, Helvetica, sans-serif" SIZE="2"><zparagraph>If you do not need to access the properties of the regular expression, an alternative way of creating <FONT FACE="courier, couriernew, monospaced size">myArray</FONT> is with this script:</zparagraph>
</FONT>
<P>
<A NAME="1008542"></A><FONT FACE="courier, couriernew, monospaced size" SIZE="2">
<zcodeline>&lt;SCRIPT LANGUAGE="JavaScript1.2"&gt;<br>
myArray = /d(b+)d/g.exec("cdbbdbsbz");<br>
&lt;/SCRIPT&gt;
</zcodeline>
</FONT>
<P>
<A NAME="1008543"> </A><FONT FACE="Arial, Helvetica, sans-serif" SIZE="2"><zparagraph>If you want to construct the regular expression from a string, yet another alternative is this script:</zparagraph>
</FONT>
<P>
<A NAME="1008544"></A><FONT FACE="courier, couriernew, monospaced size" SIZE="2">
<zcodeline>&lt;SCRIPT LANGUAGE="JavaScript1.2"&gt;<br>
myRe= new RegExp ("d(b+)d", "g");<br>
myArray = myRe.exec("cdbbdbsbz");<br>
&lt;/SCRIPT&gt;
</zcodeline>
</FONT>
<P>
<A NAME="1009660"> </A><FONT FACE="Arial, Helvetica, sans-serif" SIZE="2"><zparagraph>With these scripts, the match succeeds and returns the array and updates the properties shown in the following table.</zparagraph>
</FONT>
<P>

<P>
<A NAME="1009763"> </A>
<FONT FACE="Arial, Helvetica, sans-serif" SIZE="2">
<BR>
<P>
<TABLE WIDTH="90%" BORDER="1" CELLPADDING="5" CELLSPACING="0">
  <CAPTION></CAPTION><P><FONT FACE=""><B>
<A NAME="1009670"> </A>
<A NAME="Results of regular expression execution. &nbsp;"> </A>
<ALIGN="LEFT">
<FONT FACE="Arial, Helvetica, sans-serif" SIZE="2">
<B>
<ztablecaption>Table 4.3&#32;&nbsp&nbsp Results of regular expression execution. &nbsp;</ztablecaption>
</B>
</FONT>
</B></FONT>
<BR>
<BR>
  <TR BGCOLOR="#CCCCCC" ALIGN=LEFT VALIGN=TOP>
    <TH VALIGN=TOP ALIGN=LEFT><A NAME="1009678"> </A>
<P ALIGN="LEFT">
<FONT FACE="Arial, Helvetica, sans-serif" SIZE="2">
<B>
<ztablehead>Object</ztablehead>
</B>
</FONT>
</TH>
    <TH VALIGN=TOP ALIGN=LEFT><A NAME="1009680"> </A>
<P ALIGN="LEFT">
<FONT FACE="Arial, Helvetica, sans-serif" SIZE="2">
<B>
<ztablehead>Property or index</ztablehead>
</B>
</FONT>
</TH>
    <TH VALIGN=TOP ALIGN=LEFT><A NAME="1009682"> </A>
<P ALIGN="LEFT">
<FONT FACE="Arial, Helvetica, sans-serif" SIZE="2">
<B>
<ztablehead>Description</ztablehead>
</B>
</FONT>
</TH>
    <TH VALIGN=TOP ALIGN=LEFT><A NAME="1009684"> </A>
<P ALIGN="LEFT">
<FONT FACE="Arial, Helvetica, sans-serif" SIZE="2">
<B>
<ztablehead>In this example</ztablehead>
</B>
</FONT>
</TH>
  </DIV></TR>
  <TR>
    <TD VALIGN=TOP COLSPAN=1 ROWSPAN=4><A NAME="1009686"></A><FONT FACE="courier, couriernew, monospaced size" SIZE="2">
<zcodeline>myArray
</zcodeline>
</FONT>
<P></TD>
    <TD VALIGN=TOP><A NAME="1009688"></A><FONT FACE="courier, couriernew, monospaced size" SIZE="2">
<zcodeline>
</zcodeline>
</FONT>
<P>&nbsp;</TD>
    <TD VALIGN=TOP>
<P>
<A NAME="1009690"> </A>
<FONT FACE="Arial, Helvetica, sans-serif" SIZE="2">
<ztabletext>The matched string and all remembered substrings.</ztabletext>
</FONT>&nbsp;</TD>
    <TD VALIGN=TOP>
<P>
<A NAME="1009692"> </A>
<FONT FACE="Arial, Helvetica, sans-serif" SIZE="2">
<ztabletext><FONT FACE="courier, couriernew, monospaced size">["dbbd", "bb"]</FONT></ztabletext>
</FONT>&nbsp;</TD>
  </TR>
  <TR>
    <TD VALIGN=TOP><A NAME="1009696"></A><FONT FACE="courier, couriernew, monospaced size" SIZE="2">
<zcodeline>index
</zcodeline>
</FONT>
<P>&nbsp;</TD>
    <TD VALIGN=TOP>
<P>
<A NAME="1009698"> </A>
<FONT FACE="Arial, Helvetica, sans-serif" SIZE="2">
<ztabletext>The 0-based index of the match in the input string.</ztabletext>
</FONT>&nbsp;</TD>
    <TD VALIGN=TOP>
<P>
<A NAME="1009700"> </A>
<FONT FACE="Arial, Helvetica, sans-serif" SIZE="2">
<ztabletext><FONT FACE="courier, couriernew, monospaced size">1</FONT></ztabletext>
</FONT>&nbsp;</TD>
  </TR>
  <TR>
    <TD VALIGN=TOP><A NAME="1009704"></A><FONT FACE="courier, couriernew, monospaced size" SIZE="2">
<zcodeline>input
</zcodeline>
</FONT>
<P>&nbsp;</TD>
    <TD VALIGN=TOP>
<P>
<A NAME="1009706"> </A>
<FONT FACE="Arial, Helvetica, sans-serif" SIZE="2">
<ztabletext>The original string.</ztabletext>
</FONT>&nbsp;</TD>
    <TD VALIGN=TOP>
<P>
<A NAME="1009708"> </A>
<FONT FACE="Arial, Helvetica, sans-serif" SIZE="2">
<ztabletext><FONT FACE="courier, couriernew, monospaced size">"cdbbdbsbz"</FONT></ztabletext>
</FONT>&nbsp;</TD>
  </TR>
  <TR>
    <TD VALIGN=TOP><A NAME="1009712"></A><FONT FACE="courier, couriernew, monospaced size" SIZE="2">
<zcodeline>[0]
</zcodeline>
</FONT>
<P>&nbsp;</TD>
    <TD VALIGN=TOP>
<P>
<A NAME="1009714"> </A>
<FONT FACE="Arial, Helvetica, sans-serif" SIZE="2">
<ztabletext>The last matched characters.</ztabletext>
</FONT>&nbsp;</TD>
    <TD VALIGN=TOP>
<P>
<A NAME="1009716"> </A>
<FONT FACE="Arial, Helvetica, sans-serif" SIZE="2">
<ztabletext><FONT FACE="courier, couriernew, monospaced size">"dbbd"</FONT></ztabletext>
</FONT>&nbsp;</TD>
  </TR>
  <TR>
    <TD VALIGN=TOP COLSPAN=1 ROWSPAN=2><A NAME="1009718"></A><FONT FACE="courier, couriernew, monospaced size" SIZE="2">
<zcodeline>myRe
</zcodeline>
</FONT>
<P></TD>
    <TD VALIGN=TOP><A NAME="1009720"></A><FONT FACE="courier, couriernew, monospaced size" SIZE="2">
<zcodeline>lastIndex
</zcodeline>
</FONT>
<P>&nbsp;</TD>
    <TD VALIGN=TOP>
<P>
<A NAME="1009722"> </A>
<FONT FACE="Arial, Helvetica, sans-serif" SIZE="2">
<ztabletext>The index at which to start the next match. (This property is set only if the regular expression uses the <FONT FACE="courier, couriernew, monospaced size">g</FONT> option, described in <A HREF="regexp.html#1008681"  >Executing a Global Search, Ignoring Case, and Considering Multiline Input</A>.)</ztabletext>
</FONT>&nbsp;</TD>
    <TD VALIGN=TOP>
<P>
<A NAME="1009727"> </A>
<FONT FACE="Arial, Helvetica, sans-serif" SIZE="2">
<ztabletext><FONT FACE="courier, couriernew, monospaced size">5</FONT></ztabletext>
</FONT>&nbsp;</TD>
  </TR>
  <TR>
    <TD VALIGN=TOP><A NAME="1009731"></A><FONT FACE="courier, couriernew, monospaced size" SIZE="2">
<zcodeline>source
</zcodeline>
</FONT>
<P>&nbsp;</TD>
    <TD VALIGN=TOP>
<P>
<A NAME="1009733"> </A>
<FONT FACE="Arial, Helvetica, sans-serif" SIZE="2">
<ztabletext>The text of the pattern.Updated at the time that the regular expression is created, not executed.</ztabletext>
</FONT>&nbsp;</TD>
    <TD VALIGN=TOP>
<P>
<A NAME="1009735"> </A>
<FONT FACE="Arial, Helvetica, sans-serif" SIZE="2">
<ztabletext><FONT FACE="courier, couriernew, monospaced size">"d(b+)d"</FONT></ztabletext>
</FONT>&nbsp;</TD>
  </TR>
</TABLE>



<P>
</FONT>
<P>


<A NAME="1008649"> </A><FONT FACE="Arial, Helvetica, sans-serif" SIZE="2"><zparagraph>As shown in the second form of this example, you can use the a regular expression created with an object initializer without assigning it to a variable. If you do, however, every occurrence is a new regular expression. For this reason, if you use this form without assigning it to a variable, you cannot subsequently access the properties of that regular expression. For example, assume you have this script:</zparagraph>
</FONT>
<P>
<A NAME="1008650"></A><FONT FACE="courier, couriernew, monospaced size" SIZE="2">
<zcodeline>&lt;SCRIPT LANGUAGE="JavaScript1.2"&gt;<br>
myRe=/d(b+)d/g;<br>
myArray = myRe.exec("cdbbdbsbz");<br>
document.writeln("The value of lastIndex is " + myRe.lastIndex);<br>
&lt;/SCRIPT&gt;
</zcodeline>
</FONT>
<P>
<A NAME="1008651"> </A><FONT FACE="Arial, Helvetica, sans-serif" SIZE="2"><zparagraph>This script displays:</zparagraph>
</FONT>
<P>
<dl>  <dl>
     <DT> <A NAME="1008652"> </A>
<FONT FACE="Arial, Helvetica, sans-serif" SIZE="2">
<zparaindent1>The value of lastIndex is 5</zparaindent1>
</FONT>
<P>  </dl>
</dl>
<A NAME="1008653"> </A><FONT FACE="Arial, Helvetica, sans-serif" SIZE="2"><zparagraph>However, if you have this script:</zparagraph>
</FONT>
<P>
<A NAME="1008654"></A><FONT FACE="courier, couriernew, monospaced size" SIZE="2">
<zcodeline>&lt;SCRIPT LANGUAGE="JavaScript1.2"&gt;<br>
myArray = /d(b+)d/g.exec("cdbbdbsbz");<br>
document.writeln("The value of lastIndex is " + /d(b+)d/g.lastIndex);<br>
&lt;/SCRIPT&gt;
</zcodeline>
</FONT>
<P>
<A NAME="1008655"> </A><FONT FACE="Arial, Helvetica, sans-serif" SIZE="2"><zparagraph>It displays:</zparagraph>
</FONT>
<P>
<dl>  <dl>
     <DT> <A NAME="1008656"> </A>
<FONT FACE="Arial, Helvetica, sans-serif" SIZE="2">
<zparaindent1>The value of lastIndex is 0</zparaindent1>
</FONT>
<P>  </dl>
</dl>
<A NAME="1008657"> </A><FONT FACE="Arial, Helvetica, sans-serif" SIZE="2"><zparagraph>The occurrences of <FONT FACE="courier, couriernew, monospaced size">/d(b+)d/g</FONT> in the two statements are different regular expression objects and hence have different values for their <FONT FACE="courier, couriernew, monospaced size">lastIndex</FONT> property. If you need to access the properties of a regular expression created with an object initializer, you should first assign it to a variable.</zparagraph>
</FONT>
<P>
<P>
<BR>
<A NAME="1008659"> </A>
<A NAME="Using Parenthesized Substring Matches"> </A>
<FONT FACE="Arial, Helvetica, sans-serif" SIZE="4">
<zhead2>Using Parenthesized Substring Matches</zhead2>
</FONT>
<BR>
<BR>



<A NAME="1008660"> </A><FONT FACE="Arial, Helvetica, sans-serif" SIZE="2"><zparagraph>Including parentheses in a regular expression pattern causes the corresponding submatch to be remembered. For example, <FONT FACE="courier, couriernew, monospaced size">/a(b)c/</FONT> matches the characters 'abc' and remembers 'b'. To recall these parenthesized substring matches, use the <FONT FACE="courier, couriernew, monospaced size">Array</FONT> elements <FONT FACE="courier, couriernew, monospaced size">[1]</FONT>, ..., <FONT FACE="courier, couriernew, monospaced size">[n]</FONT>.</zparagraph>
</FONT>
<P>

<A NAME="1008661"> </A><FONT FACE="Arial, Helvetica, sans-serif" SIZE="2"><zparagraph>The number of possible parenthesized substrings is unlimited. The returned array holds all that were found. The following examples illustrate how to use parenthesized substring matches.</zparagraph>
</FONT>
<P>
<P>
<A NAME="1008662"> </A>
<FONT FACE="Arial, Helvetica, sans-serif" SIZE="2">
<B>
<zheadrunin>Example 1. </zheadrunin>
</B>
</FONT>

<A NAME="1008663"> </A><FONT FACE="Arial, Helvetica, sans-serif" SIZE="2"><zparagraph>The following script uses the <FONT FACE="courier, couriernew, monospaced size">replace</FONT> method to switch the words in the string. For the replacement text, the script uses the <FONT FACE="courier, couriernew, monospaced size">$1</FONT> and <FONT FACE="courier, couriernew, monospaced size">$2</FONT> in the replacement to denote the first string and second parenthesized substring match.</zparagraph>
</FONT>
<P>
<A NAME="1008664"></A><FONT FACE="courier, couriernew, monospaced size" SIZE="2">
<zcodeline>&lt;SCRIPT LANGUAGE="JavaScript1.2"&gt;<br>
re = /(\w+)\s(\w+)/;<br>
str = "John Smith";<br>
newstr = str.replace(re, "$2, $1");<br>
document.write(newstr)<br>
&lt;/SCRIPT&gt;
</zcodeline>
</FONT>
<P>
<A NAME="1008665"> </A><FONT FACE="Arial, Helvetica, sans-serif" SIZE="2"><zparagraph>This prints "Smith, John".</zparagraph>
</FONT>
<P>
<P>
<A NAME="1008666"> </A>
<FONT FACE="Arial, Helvetica, sans-serif" SIZE="2">
<B>
<zheadrunin>Example 2. </zheadrunin>
</B>
</FONT>

<A NAME="1008667"> </A><FONT FACE="Arial, Helvetica, sans-serif" SIZE="2"><zparagraph>In the following example, <FONT FACE="courier, couriernew, monospaced size">RegExp.input</FONT> is set by the Change event. In the <FONT FACE="courier, couriernew, monospaced size">getInfo</FONT> function, the <FONT FACE="courier, couriernew, monospaced size">exec</FONT> method, called using the () shortcut notation, uses the value of <FONT FACE="courier, couriernew, monospaced size">RegExp.input</FONT> as its argument. </zparagraph>
</FONT>
<P>
<A NAME="1008675"></A><FONT FACE="courier, couriernew, monospaced size" SIZE="2">
<zcodeline>&lt;HTML&gt;
</zcodeline>
</FONT>
<P><A NAME="1008676"></A><FONT FACE="courier, couriernew, monospaced size" SIZE="2">
<zcodeline>&lt;SCRIPT LANGUAGE="JavaScript1.2"&gt;<br>
function getInfo(){<br>
&nbsp;&nbsp;&nbsp;a = /(\w+)\s(\d+)/();<br>
&nbsp;&nbsp;&nbsp;window.alert(a[1] + ", your age is " + a[2]);<br>
}<br>
&lt;/SCRIPT&gt;
</zcodeline>
</FONT>
<P><A NAME="1008677"></A><FONT FACE="courier, couriernew, monospaced size" SIZE="2">
<zcodeline>Enter your first name and your age, and then press Enter.
</zcodeline>
</FONT>
<P><A NAME="1008678"></A><FONT FACE="courier, couriernew, monospaced size" SIZE="2">
<zcodeline>&lt;FORM&gt;<br>
&lt;INPUT TYPE="text" NAME="NameAge" onChange="getInfo(this);"&gt;<br>
&lt;/FORM&gt;
</zcodeline>
</FONT>
<P><A NAME="1008679"></A><FONT FACE="courier, couriernew, monospaced size" SIZE="2">
<zcodeline>&lt;/HTML&gt;
</zcodeline>
</FONT>
<P><P>
<BR>
<A NAME="1008681"> </A>
<A NAME="Executing a Global Search, Ignoring Case, and Considering Multiline Input"> </A>
<FONT FACE="Arial, Helvetica, sans-serif" SIZE="4">
<zhead2>Executing a Global Search, Ignoring Case, and Considering Multiline Input</zhead2>
</FONT>
<BR>
<BR>



<A NAME="1008682"> </A><FONT FACE="Arial, Helvetica, sans-serif" SIZE="2"><zparagraph>Regular expressions have three optional flags that allow for global and case insensitive searching. To indicate a global search, use the <FONT FACE="courier, couriernew, monospaced size">g</FONT> flag. To indicate a case-insensitive search, use the <FONT FACE="courier, couriernew, monospaced size">i</FONT> flag. To indicate a multi-line search, use the <FONT FACE="courier, couriernew, monospaced size">m</FONT> flag. These flags can be used separately or together in any order, and are included as part of the regular expression.</zparagraph>
</FONT>
<P>

<A NAME="1008683"> </A><FONT FACE="Arial, Helvetica, sans-serif" SIZE="2"><zparagraph>To include a flag with the regular expression, use this syntax:</zparagraph>
</FONT>
<P>
<A NAME="1008684"></A><FONT FACE="courier, couriernew, monospaced size" SIZE="2">
<zcodeline>re = /pattern/flags<br>
re = new RegExp("pattern", ["flags"])
</zcodeline>
</FONT>
<P>
<A NAME="1008685"> </A><FONT FACE="Arial, Helvetica, sans-serif" SIZE="2"><zparagraph>Note that the flags are an integral part of a regular expression. They cannot be added or removed later.</zparagraph>
</FONT>
<P>

<A NAME="1008686"> </A><FONT FACE="Arial, Helvetica, sans-serif" SIZE="2"><zparagraph>For example, <FONT FACE="courier, couriernew, monospaced size">re&nbsp;=&nbsp;/\w+\s/g</FONT> creates a regular expression that looks for one or more characters followed by a space, and it looks for this combination throughout the string.</zparagraph>
</FONT>
<P>
<A NAME="1008687"></A><FONT FACE="courier, couriernew, monospaced size" SIZE="2">
<zcodeline>&lt;SCRIPT LANGUAGE="JavaScript1.2"&gt;<br>
re = /\w+\s/g;<br>
str = "fee fi fo fum";<br>
myArray = str.match(re);<br>
document.write(myArray);<br>
&lt;/SCRIPT&gt;
</zcodeline>
</FONT>
<P>
<A NAME="1008688"> </A><FONT FACE="Arial, Helvetica, sans-serif" SIZE="2"><zparagraph>This displays ["fee ", "fi ", "fo "]. In this example, you could replace the line:</zparagraph>
</FONT>
<P>
<A NAME="1008689"></A><FONT FACE="courier, couriernew, monospaced size" SIZE="2">
<zcodeline>re = /\w+\s/g;
</zcodeline>
</FONT>
<P>
<A NAME="1008690"> </A><FONT FACE="Arial, Helvetica, sans-serif" SIZE="2"><zparagraph>with:</zparagraph>
</FONT>
<P>
<A NAME="1008691"></A><FONT FACE="courier, couriernew, monospaced size" SIZE="2">
<zcodeline>re = new RegExp("\\w+\\s", "g");
</zcodeline>
</FONT>
<P>
<A NAME="1008692"> </A><FONT FACE="Arial, Helvetica, sans-serif" SIZE="2"><zparagraph>and get the same result.</zparagraph>
</FONT>
<P>

<A NAME="1013060"> </A><FONT FACE="Arial, Helvetica, sans-serif" SIZE="2"><zparagraph>The <FONT FACE="courier, couriernew, monospaced size">m</FONT> flag is used to specify that a multiline input string should be treated as multiple lines. If the <FONT FACE="courier, couriernew, monospaced size">m</FONT> flag is used, <FONT FACE="courier, couriernew, monospaced size">^</FONT> and <FONT FACE="courier, couriernew, monospaced size">$</FONT> match at the start or end of any line within the input string instead of the start or end of the entire string.</zparagraph>
</FONT>
<P>

<BR>
<BR>

<A NAME="1013064"> </A>
<A NAME="Examples"> </A>
<FONT FACE="Arial, Helvetica, sans-serif" SIZE="4">
<zhead1>Examples</zhead1>
<HR SIZE="2" NOSHADE>
</FONT>
<BR>


<A NAME="1010172"> </A><FONT FACE="Arial, Helvetica, sans-serif" SIZE="2"><zparagraph>The following examples show some uses of regular expressions.</zparagraph>
</FONT>
<P>
<P>
<BR>
<A NAME="1008695"> </A>
<A NAME="Changing the Order in an Input String"> </A>
<FONT FACE="Arial, Helvetica, sans-serif" SIZE="4">
<zhead2>Changing the Order in an Input String</zhead2>
</FONT>
<BR>
<BR>



<A NAME="1008696"> </A><FONT FACE="Arial, Helvetica, sans-serif" SIZE="2"><zparagraph>The following example illustrates the formation of regular expressions and the use of <FONT FACE="courier, couriernew, monospaced size">string.split()</FONT> and <FONT FACE="courier, couriernew, monospaced size">string.replace()</FONT>. It cleans a roughly formatted input string containing names (first name first) separated by blanks, tabs and exactly one semicolon. Finally, it reverses the name order (last name first) and sorts the list.</zparagraph>
</FONT>
<P>
<A NAME="1008699"></A><FONT FACE="courier, couriernew, monospaced size" SIZE="2">
<zcodeline>&lt;SCRIPT LANGUAGE="JavaScript1.2"&gt;
</zcodeline>
</FONT>
<P><A NAME="1008700"></A><FONT FACE="courier, couriernew, monospaced size" SIZE="2">
<zcodeline>// The name string contains multiple spaces and tabs,<br>
// and may have multiple spaces between first and last names.<br>
names = new String ( "Harry Trump ;Fred Barney; Helen Rigby ;\<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Bill Abel ;Chris Hand ")
</zcodeline>
</FONT>
<P><A NAME="1008701"></A><FONT FACE="courier, couriernew, monospaced size" SIZE="2">
<zcodeline>document.write ("---------- Original String" + "&lt;BR&gt;" + "&lt;BR&gt;");<br>
document.write (names + "&lt;BR&gt;" + "&lt;BR&gt;");
</zcodeline>
</FONT>
<P><A NAME="1008702"></A><FONT FACE="courier, couriernew, monospaced size" SIZE="2">
<zcodeline>// Prepare two regular expression patterns and array storage.<br>
// Split the string into array elements.
</zcodeline>
</FONT>
<P><A NAME="1008703"></A><FONT FACE="courier, couriernew, monospaced size" SIZE="2">
<zcodeline>// pattern: possible white space then semicolon then possible white space<br>
pattern = /\s*;\s*/;
</zcodeline>
</FONT>
<P><A NAME="1008704"></A><FONT FACE="courier, couriernew, monospaced size" SIZE="2">
<zcodeline>// Break the string into pieces separated by the pattern above and<br>
// and store the pieces in an array called nameList<br>
nameList = names.split (pattern);
</zcodeline>
</FONT>
<P><A NAME="1008705"></A><FONT FACE="courier, couriernew, monospaced size" SIZE="2">
<zcodeline>// new pattern: one or more characters then spaces then characters.<br>
// Use parentheses to "memorize" portions of the pattern.<br>
// The memorized portions are referred to later.<br>
pattern = /(\w+)\s+(\w+)/;
</zcodeline>
</FONT>
<P><A NAME="1008706"></A><FONT FACE="courier, couriernew, monospaced size" SIZE="2">
<zcodeline>// New array for holding names being processed.<br>
bySurnameList = new Array;
</zcodeline>
</FONT>
<P><A NAME="1008707"></A><FONT FACE="courier, couriernew, monospaced size" SIZE="2">
<zcodeline>// Display the name array and populate the new array<br>
// with comma-separated names, last first.<br>
//<br>
// The replace method removes anything matching the pattern<br>
// and replaces it with the memorized string&#151;second memorized portion<br>
// followed by comma space followed by first memorized portion.<br>
// <br>
// The variables $1 and $2 refer to the portions<br>
// memorized while matching the pattern.
</zcodeline>
</FONT>
<P><A NAME="1008708"></A><FONT FACE="courier, couriernew, monospaced size" SIZE="2">
<zcodeline>document.write ("---------- After Split by Regular Expression" + "&lt;BR&gt;");<br>
for ( i = 0; i &lt; nameList.length; i++) {<br>
&nbsp;&nbsp;&nbsp;document.write (nameList[i] + "&lt;BR&gt;");<br>
&nbsp;&nbsp;&nbsp;bySurnameList[i] = nameList[i].replace (pattern, "$2, $1")<br>
}
</zcodeline>
</FONT>
<P><A NAME="1008709"></A><FONT FACE="courier, couriernew, monospaced size" SIZE="2">
<zcodeline>// Display the new array.<br>
document.write ("---------- Names Reversed" + "&lt;BR&gt;");<br>
for ( i = 0; i &lt; bySurnameList.length; i++) {<br>
&nbsp;&nbsp;&nbsp;document.write (bySurnameList[i] + "&lt;BR&gt;")<br>
}
</zcodeline>
</FONT>
<P><A NAME="1008710"></A><FONT FACE="courier, couriernew, monospaced size" SIZE="2">
<zcodeline>// Sort by last name, then display the sorted array.<br>
bySurnameList.sort();<br>
document.write ("---------- Sorted" + "&lt;BR&gt;");<br>
for ( i = 0; i &lt; bySurnameList.length; i++) {<br>
&nbsp;&nbsp;&nbsp;document.write (bySurnameList[i] + "&lt;BR&gt;")<br>
}
</zcodeline>
</FONT>
<P><A NAME="1008711"></A><FONT FACE="courier, couriernew, monospaced size" SIZE="2">
<zcodeline>document.write ("---------- End" + "&lt;BR&gt;")
</zcodeline>
</FONT>
<P><A NAME="1008712"></A><FONT FACE="courier, couriernew, monospaced size" SIZE="2">
<zcodeline>&lt;/SCRIPT&gt;
</zcodeline>
</FONT>
<P><P>
<BR>
<A NAME="1008713"> </A>
<A NAME="Using Special Characters to Verify Input"> </A>
<FONT FACE="Arial, Helvetica, sans-serif" SIZE="4">
<zhead2>Using Special Characters to Verify Input</zhead2>
</FONT>
<BR>
<BR>



<A NAME="1008714"> </A><FONT FACE="Arial, Helvetica, sans-serif" SIZE="2"><zparagraph>In the following example, a user enters a phone number. When the user presses Enter, the script checks the validity of the number. If the number is valid (matches the character sequence specified by the regular expression), the script posts a window thanking the user and confirming the number. If the number is invalid, the script posts a window informing the user that the phone number is not valid.</zparagraph>
</FONT>
<P>

<A NAME="1008715"> </A><FONT FACE="Arial, Helvetica, sans-serif" SIZE="2"><zparagraph>The regular expression looks for zero or one open parenthesis <FONT FACE="courier, couriernew, monospaced size">\(?</FONT>, followed by three digits <FONT FACE="courier, couriernew, monospaced size">\d{3}</FONT>, followed by zero or one close parenthesis <FONT FACE="courier, couriernew, monospaced size">\)?</FONT>, followed by one dash, forward slash, or decimal point and when found, remember the character <FONT FACE="courier, couriernew, monospaced size">([-\/\.])</FONT>, followed by three digits <FONT FACE="courier, couriernew, monospaced size">\d{3}</FONT>, followed by the remembered match of a dash, forward slash, or decimal point <FONT FACE="courier, couriernew, monospaced size">\1</FONT>, followed by four digits <FONT FACE="courier, couriernew, monospaced size">\d{4}</FONT>.</zparagraph>
</FONT>
<P>

<A NAME="1008716"> </A><FONT FACE="Arial, Helvetica, sans-serif" SIZE="2"><zparagraph>The Change event activated when the user presses Enter sets the value of <FONT FACE="courier, couriernew, monospaced size">RegExp.input</FONT>.</zparagraph>
</FONT>
<P>
<A NAME="1008717"></A><FONT FACE="courier, couriernew, monospaced size" SIZE="2">
<zcodeline>&lt;HTML&gt;<br>
&lt;SCRIPT LANGUAGE = "JavaScript1.2"&gt;
</zcodeline>
</FONT>
<P><A NAME="1008718"></A><FONT FACE="courier, couriernew, monospaced size" SIZE="2">
<zcodeline>re = /\(?\d{3}\)?([-\/\.])\d{3}\1\d{4}/;
</zcodeline>
</FONT>
<P><A NAME="1008719"></A><FONT FACE="courier, couriernew, monospaced size" SIZE="2">
<zcodeline>function testInfo() {<br>
&nbsp;&nbsp;&nbsp;OK = re.exec();<br>
&nbsp;&nbsp;&nbsp;if (!OK)<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;window.alert (RegExp.input + <br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;" isn't a phone number with area code!")<br>
&nbsp;&nbsp;&nbsp;else<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;window.alert ("Thanks, your phone number is " + OK[0])<br>
}
</zcodeline>
</FONT>
<P><A NAME="1008720"></A><FONT FACE="courier, couriernew, monospaced size" SIZE="2">
<zcodeline>&lt;/SCRIPT&gt;
</zcodeline>
</FONT>
<P><A NAME="1008721"></A><FONT FACE="courier, couriernew, monospaced size" SIZE="2">
<zcodeline>Enter your phone number (with area code) and then press Enter.<br>
&lt;FORM&gt; <br>
&lt;INPUT TYPE="text" NAME="Phone" onChange="testInfo(this);"&gt;<br>
&lt;/FORM&gt;
</zcodeline>
</FONT>
<P><A NAME="1008722"></A><FONT FACE="courier, couriernew, monospaced size" SIZE="2">
<zcodeline>&lt;/HTML&gt;
</zcodeline>
</FONT>
<P>


   </BLOCKQUOTE>
</BOOKCONTENT>

<FOOTERCONTENT>
   <BLOCKQUOTE>
 <BR>
            <b><a href="expr.html">
<FONT FACE="Arial, Helvetica, sans-serif" SIZE="2" COLOR="#993300">Previous</a></FONT>&nbsp;&nbsp;&nbsp;&nbsp;</b>
<a href="contents.html">
<b><FONT FACE="Arial, Helvetica, sans-serif" SIZE="2" COLOR="#993300">Contents</a></FONT></b>&nbsp;&nbsp;&nbsp;&nbsp;
<a href="ix.html"><b><FONT FACE="Arial, Helvetica, sans-serif" SIZE="2" COLOR="#993300">Index</a></FONT></b>&nbsp;&nbsp;&nbsp;&nbsp;
<a href="stmtsov.html">
<b>
<FONT FACE="Arial, Helvetica, sans-serif" SIZE="2" COLOR="#993300">
Next
</a>
</FONT>
</b>&nbsp;&nbsp;&nbsp;&nbsp;
        <HR NOSHADE SIZE="1">


   <font face="Arial, Helvetica, sans-serif" SIZE="1">

Copyright &#169; 2000 <a href="http://www.netscape.com">Netscape Communications Corp.</a> All rights reserved.</FONT>
   </BLOCKQUOTE>
   <FONT FACE="Arial, Helvetica, sans-serif" SIZE="1">
   <P ALIGN="RIGHT">Last Updated <B>September 28, 2000</B>
   </FONT>
   <BR>

</FOOTERCONTENT>

</MAINCONTENT>

</BODY>


</HTML>